cmake_minimum_required(VERSION 3.18)
project(unified-cache-management VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(BUILD_UCM_STORE "build ucm store module." ON)
option(BUILD_UCM_SPARSE "build ucm sparse module." OFF)
option(BUILD_UNIT_TESTS "build all unit test suits." OFF)
option(BUILD_NUMA "build numactl library." OFF)
option(DOWNLOAD_DEPENDENCE "download dependence by cmake." ON)
set(RUNTIME_ENVIRONMENT "simu" CACHE STRING "runtime: simu, ascend, musa or cuda.")
set(LOGGER_BACKEND "spdlog" CACHE STRING "backend: spdlog or flux.")

execute_process(COMMAND git rev-parse HEAD OUTPUT_VARIABLE UCM_COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE)
add_compile_definitions(UCM_PROJECT_NAME="${PROJECT_NAME}")
add_compile_definitions(UCM_PROJECT_VERSION="${PROJECT_VERSION}")
add_compile_definitions(UCM_COMMIT_ID="${UCM_COMMIT_ID}")
add_compile_definitions(UCM_BUILD_TYPE="${CMAKE_BUILD_TYPE}")

set(CMAKE_SKIP_RPATH TRUE)
set(FLAGS_PUBLIC "-Wall -Werror -fPIC -Wl,-z,relro,-z,now")
set(FLAGS_DEBUG "-O0 -g")
set(FLAGS_RELEASE "-O3 -D_FORTIFY_SOURCE=2")
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS_PUBLIC} ${FLAGS_DEBUG}")
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS_PUBLIC} ${FLAGS_RELEASE}")
endif()
if(BUILD_UNIT_TESTS)
    enable_testing()
endif()

add_subdirectory(ucm)
if(BUILD_UNIT_TESTS)
    add_subdirectory(test)
endif()
